package reflect;

import java.lang.reflect.Method;

/**
 * @Classname: Test2
 * @Author: bromide
 * @CreateTime: 2022/4/18--14:34
 * @Version: V1.0
 * @Description: 自动调用reflect.Person类中所有无参方法
 */
public class Test2 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        Method[] methods = cls.getMethods();
        for (Method method : methods) {
            if (method.getName().contains("say") && method.getParameterCount() == 0) {
                method.invoke(obj);
            }
        }
    }
}
